<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.9.1"/>
<title>CMU462 Library: /Users/Sky/Dropbox/Projects/CMU462/private/p3/CMU462/include/CMU462/color.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { init_search(); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">CMU462 Library
   &#160;<span id="projectnumber">1.0</span>
   </div>
   <div id="projectbrief">15-462/15-662: Computer Graphics (Fall 2015)</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.9.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="dir_93cde9e1f49b119e2b24d2ae2dcc682a.html">CMU462</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">color.h</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="preprocessor">#ifndef CMU462_COLOR_H</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="preprocessor">#define CMU462_COLOR_H</span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;</div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="preprocessor">#include &quot;CMU462.h&quot;</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;</div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="preprocessor">#include &lt;string&gt;</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;</div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespace_c_m_u462.html">CMU462</a> {</div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;</div>
<div class="line"><a name="l00015"></a><span class="lineno"><a class="line" href="class_c_m_u462_1_1_color.html">   15</a></span>&#160;<span class="keyword">class </span><a class="code" href="class_c_m_u462_1_1_color.html">Color</a> {</div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160; <span class="keyword">public</span>:</div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;</div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;  <span class="comment">// Components.</span></div>
<div class="line"><a name="l00019"></a><span class="lineno"><a class="line" href="class_c_m_u462_1_1_color.html#ae925fc295f8f5dcdaacf851e8c4880cb">   19</a></span>&#160;  <span class="keywordtype">float</span> <a class="code" href="class_c_m_u462_1_1_color.html#ae925fc295f8f5dcdaacf851e8c4880cb">r</a>; </div>
<div class="line"><a name="l00020"></a><span class="lineno"><a class="line" href="class_c_m_u462_1_1_color.html#a4a3179778bc75342961e5b96a1b8b228">   20</a></span>&#160;  <span class="keywordtype">float</span> <a class="code" href="class_c_m_u462_1_1_color.html#a4a3179778bc75342961e5b96a1b8b228">g</a>; </div>
<div class="line"><a name="l00021"></a><span class="lineno"><a class="line" href="class_c_m_u462_1_1_color.html#a5ae56ddf662d80a6cfd423664d99d648">   21</a></span>&#160;  <span class="keywordtype">float</span> <a class="code" href="class_c_m_u462_1_1_color.html#a5ae56ddf662d80a6cfd423664d99d648">b</a>; </div>
<div class="line"><a name="l00022"></a><span class="lineno"><a class="line" href="class_c_m_u462_1_1_color.html#af4499c6f417283b77c3fa38697df65c0">   22</a></span>&#160;  <span class="keywordtype">float</span> <a class="code" href="class_c_m_u462_1_1_color.html#af4499c6f417283b77c3fa38697df65c0">a</a>; </div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;  <span class="comment">// constants</span></div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;  <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="class_c_m_u462_1_1_color.html">Color</a> White;</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;  <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="class_c_m_u462_1_1_color.html">Color</a> Black;</div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;</div>
<div class="line"><a name="l00037"></a><span class="lineno"><a class="line" href="class_c_m_u462_1_1_color.html#ae6acb0aab5c9be2fe91b7d3d7ca1b3e4">   37</a></span>&#160;  <a class="code" href="class_c_m_u462_1_1_color.html#ae6acb0aab5c9be2fe91b7d3d7ca1b3e4">Color</a>( <span class="keywordtype">float</span> r = 0, <span class="keywordtype">float</span> g = 0, <span class="keywordtype">float</span> b = 0, <span class="keywordtype">float</span> a = 1.0 )</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;      : r( r ), g( g ), b( b ), a( a ) { }</div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;  <a class="code" href="class_c_m_u462_1_1_color.html#ae6acb0aab5c9be2fe91b7d3d7ca1b3e4">Color</a>( <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* arr );</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;  <span class="comment">// Addition. Alpha is ignored.</span></div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;  <span class="keyword">inline</span> <a class="code" href="class_c_m_u462_1_1_color.html">Color</a> operator+( <span class="keyword">const</span> <a class="code" href="class_c_m_u462_1_1_color.html">Color</a>&amp; rhs )<span class="keyword"> const </span>{</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="class_c_m_u462_1_1_color.html#ae6acb0aab5c9be2fe91b7d3d7ca1b3e4">Color</a>( r + rhs.<a class="code" href="class_c_m_u462_1_1_color.html#ae925fc295f8f5dcdaacf851e8c4880cb">r</a>, g + rhs.<a class="code" href="class_c_m_u462_1_1_color.html#a4a3179778bc75342961e5b96a1b8b228">g</a>, b + rhs.<a class="code" href="class_c_m_u462_1_1_color.html#a5ae56ddf662d80a6cfd423664d99d648">b</a>, a + rhs.<a class="code" href="class_c_m_u462_1_1_color.html#af4499c6f417283b77c3fa38697df65c0">a</a>);</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;  }</div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;</div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;  <span class="keyword">inline</span> <a class="code" href="class_c_m_u462_1_1_color.html#ae6acb0aab5c9be2fe91b7d3d7ca1b3e4">Color</a>&amp; operator+=( <span class="keyword">const</span> <a class="code" href="class_c_m_u462_1_1_color.html#ae6acb0aab5c9be2fe91b7d3d7ca1b3e4">Color</a>&amp; rhs ) {</div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;    r += rhs.r; g += rhs.g; b += rhs.b; a += rhs.a;</div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;    <span class="keywordflow">return</span> *<span class="keyword">this</span>;</div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;  }</div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;</div>
<div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;  <span class="comment">// Vector multiplication. Alpha is ignored.</span></div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;  <span class="keyword">inline</span> <a class="code" href="class_c_m_u462_1_1_color.html#ae6acb0aab5c9be2fe91b7d3d7ca1b3e4">Color</a> operator*( <span class="keyword">const</span> <a class="code" href="class_c_m_u462_1_1_color.html#ae6acb0aab5c9be2fe91b7d3d7ca1b3e4">Color</a>&amp; rhs )<span class="keyword"> const </span>{</div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="class_c_m_u462_1_1_color.html#ae6acb0aab5c9be2fe91b7d3d7ca1b3e4">Color</a>( r * rhs.r, g * rhs.g, b * rhs.b, a * rhs.a);</div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;  }</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;</div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;  <span class="keyword">inline</span> <a class="code" href="class_c_m_u462_1_1_color.html#ae6acb0aab5c9be2fe91b7d3d7ca1b3e4">Color</a>&amp; operator*=( <span class="keyword">const</span> <a class="code" href="class_c_m_u462_1_1_color.html#ae6acb0aab5c9be2fe91b7d3d7ca1b3e4">Color</a>&amp; rhs ) {</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;    r *= rhs.r; g *= rhs.g; b *= rhs.b; a *= rhs.a;</div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;    <span class="keywordflow">return</span> *<span class="keyword">this</span>;</div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;  }</div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;</div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;  <span class="comment">// Scalar multiplication.</span></div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;  <span class="keyword">inline</span> <a class="code" href="class_c_m_u462_1_1_color.html#ae6acb0aab5c9be2fe91b7d3d7ca1b3e4">Color</a> operator*( <span class="keywordtype">float</span> s )<span class="keyword"> const </span>{</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="class_c_m_u462_1_1_color.html#ae6acb0aab5c9be2fe91b7d3d7ca1b3e4">Color</a>( r * s, g * s, b * s, a * s );</div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;  }</div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;</div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;  <span class="keyword">inline</span> <a class="code" href="class_c_m_u462_1_1_color.html#ae6acb0aab5c9be2fe91b7d3d7ca1b3e4">Color</a>&amp; operator*=( <span class="keywordtype">float</span> s ) {</div>
<div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;    r *= s; g *= s; b *= s; a *= s;</div>
<div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;    <span class="keywordflow">return</span> *<span class="keyword">this</span>;</div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;  }</div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;</div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;  <span class="comment">// comparison</span></div>
<div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;  <span class="keyword">inline</span> <span class="keywordtype">bool</span> operator==( <span class="keyword">const</span> <a class="code" href="class_c_m_u462_1_1_color.html#ae6acb0aab5c9be2fe91b7d3d7ca1b3e4">Color</a>&amp; rhs )<span class="keyword"> const </span>{</div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;    <span class="keywordflow">return</span> r == rhs.r &amp;&amp; g == rhs.g &amp;&amp; b == rhs.b &amp;&amp; a == rhs.a;</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;  }</div>
<div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;</div>
<div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;  <span class="keyword">inline</span> <span class="keywordtype">bool</span> operator!=( <span class="keyword">const</span> <a class="code" href="class_c_m_u462_1_1_color.html#ae6acb0aab5c9be2fe91b7d3d7ca1b3e4">Color</a>&amp; rhs )<span class="keyword"> const </span>{</div>
<div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;    <span class="keywordflow">return</span> !operator==( rhs );</div>
<div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;  }</div>
<div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;</div>
<div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;  <span class="keyword">static</span> <a class="code" href="class_c_m_u462_1_1_color.html#ae6acb0aab5c9be2fe91b7d3d7ca1b3e4">Color</a> <a class="code" href="class_c_m_u462_1_1_color.html#ab558b2442c4b1ce94aa06181672c9da8">fromHex</a>( <span class="keyword">const</span> <span class="keywordtype">char</span>* s );</div>
<div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;</div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;  std::string <a class="code" href="class_c_m_u462_1_1_color.html#a7cd9978ae467f8979d3ab24b7096a4ad">toHex</a>( ) <span class="keyword">const</span>;</div>
<div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;</div>
<div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;</div>
<div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;}; <span class="comment">// class Color</span></div>
<div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;</div>
<div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;</div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;<span class="comment">// Commutable scalar multiplication.</span></div>
<div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;<span class="keyword">inline</span> Color operator*( <span class="keywordtype">float</span> s, <span class="keyword">const</span> Color&amp; c ) {</div>
<div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;  <span class="keywordflow">return</span> c * s;</div>
<div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;}</div>
<div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;</div>
<div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;<span class="comment">// Prints components.</span></div>
<div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;std::ostream&amp; operator&lt;&lt;( std::ostream&amp; os, <span class="keyword">const</span> Color&amp; c );</div>
<div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;</div>
<div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;} <span class="comment">// namespace CMU462</span></div>
<div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;</div>
<div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="ttc" id="namespace_c_m_u462_html"><div class="ttname"><a href="namespace_c_m_u462.html">CMU462</a></div><div class="ttdef"><b>Definition:</b> CMU462.h:8</div></div>
<div class="ttc" id="class_c_m_u462_1_1_color_html_af4499c6f417283b77c3fa38697df65c0"><div class="ttname"><a href="class_c_m_u462_1_1_color.html#af4499c6f417283b77c3fa38697df65c0">CMU462::Color::a</a></div><div class="ttdeci">float a</div><div class="ttdoc">value of alpha chanel </div><div class="ttdef"><b>Definition:</b> color.h:22</div></div>
<div class="ttc" id="class_c_m_u462_1_1_color_html_ab558b2442c4b1ce94aa06181672c9da8"><div class="ttname"><a href="class_c_m_u462_1_1_color.html#ab558b2442c4b1ce94aa06181672c9da8">CMU462::Color::fromHex</a></div><div class="ttdeci">static Color fromHex(const char *s)</div><div class="ttdoc">Construct a Color object from a hexadecimal (8-bit per component) ASCII string. </div><div class="ttdef"><b>Definition:</b> color.cpp:24</div></div>
<div class="ttc" id="class_c_m_u462_1_1_color_html_ae925fc295f8f5dcdaacf851e8c4880cb"><div class="ttname"><a href="class_c_m_u462_1_1_color.html#ae925fc295f8f5dcdaacf851e8c4880cb">CMU462::Color::r</a></div><div class="ttdeci">float r</div><div class="ttdoc">value of red chanel </div><div class="ttdef"><b>Definition:</b> color.h:19</div></div>
<div class="ttc" id="class_c_m_u462_1_1_color_html_a4a3179778bc75342961e5b96a1b8b228"><div class="ttname"><a href="class_c_m_u462_1_1_color.html#a4a3179778bc75342961e5b96a1b8b228">CMU462::Color::g</a></div><div class="ttdeci">float g</div><div class="ttdoc">value of green chanel </div><div class="ttdef"><b>Definition:</b> color.h:20</div></div>
<div class="ttc" id="class_c_m_u462_1_1_color_html_a7cd9978ae467f8979d3ab24b7096a4ad"><div class="ttname"><a href="class_c_m_u462_1_1_color.html#a7cd9978ae467f8979d3ab24b7096a4ad">CMU462::Color::toHex</a></div><div class="ttdeci">std::string toHex() const </div><div class="ttdoc">Returns a hexadecimal string rrggbb encoding this color. </div><div class="ttdef"><b>Definition:</b> color.cpp:55</div></div>
<div class="ttc" id="class_c_m_u462_1_1_color_html_a5ae56ddf662d80a6cfd423664d99d648"><div class="ttname"><a href="class_c_m_u462_1_1_color.html#a5ae56ddf662d80a6cfd423664d99d648">CMU462::Color::b</a></div><div class="ttdeci">float b</div><div class="ttdoc">value of blue chanel </div><div class="ttdef"><b>Definition:</b> color.h:21</div></div>
<div class="ttc" id="class_c_m_u462_1_1_color_html"><div class="ttname"><a href="class_c_m_u462_1_1_color.html">CMU462::Color</a></div><div class="ttdoc">Encodes a color via additive red, green, and blue chanel values. </div><div class="ttdef"><b>Definition:</b> color.h:15</div></div>
<div class="ttc" id="class_c_m_u462_1_1_color_html_ae6acb0aab5c9be2fe91b7d3d7ca1b3e4"><div class="ttname"><a href="class_c_m_u462_1_1_color.html#ae6acb0aab5c9be2fe91b7d3d7ca1b3e4">CMU462::Color::Color</a></div><div class="ttdeci">Color(float r=0, float g=0, float b=0, float a=1.0)</div><div class="ttdoc">Constructor. </div><div class="ttdef"><b>Definition:</b> color.h:37</div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Sat Oct 10 2015 03:34:42 for CMU462 Library by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.9.1
</small></address>
</body>
</html>
